package com;

public class User {
	private String username;
	private String password;
	private boolean isAdmin;
	private boolean loggedIn;
	
	private UsersManager usersManager = new UsersManager();
	
	public boolean login(String username, String password, String sessionID){
		boolean result = usersManager.queryUser(username, password, sessionID);
		if (result){
			this.username = username;
			this.password = password;
		}
		return result;
	}
	
	public void logout(String sessionID){
		usersManager.resetSession(sessionID);
	}
	
	public boolean loggedIn(String sessionID){
		// 2 = admin, 1 = user, 0 = logged out
		boolean result = (getSessionInfo(sessionID) != 0);
		loggedIn = result;
		return result;
	}
	
	public boolean isAdmin(String sessionID){
		// 2 = admin, 1 = user, 0 = logged out
		boolean result = (getSessionInfo(sessionID) == 2);
		isAdmin = result;
		return result;
	}
	
	private int getSessionInfo(String sessionID){
		return usersManager.querySession(sessionID);
	}
}